package trungnt.wipeoff;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Stage;

import trungnt.wipeoff.enums.ButtonEnum;
import trungnt.wipeoff.model.ButtonActor;
import trungnt.wipeoff.model.GameState;

public class MenuState extends GameState {

	// private GameScreen _game = null;
	// private Stage _stage = null;

	private ButtonActor button1 = null;
	private ButtonActor button2 = null;
	private ButtonActor button3 = null;
	private ButtonActor button4 = null;

	public MenuState(GameScreen game, Stage stage) {
		super(game, stage);

		// this._game = game;
		// this._stage = this.getGame().getStage();

		this.button1 = new ButtonActor(this, ButtonEnum.NEWGAME);
		this.button2 = new ButtonActor(this, ButtonEnum.RANKING);
		this.button3 = new ButtonActor(this, ButtonEnum.HOWTOPLAY);
		this.button4 = new ButtonActor(this, ButtonEnum.EXIT);

		this.getStage().addActor(this.button1);
		this.getStage().addActor(this.button2);
		this.getStage().addActor(this.button3);
		this.getStage().addActor(this.button4);

		Gdx.input.setInputProcessor(this.getStage());
	}

	@Override
	public void render(float delta) {
		// Gdx.app.log("TrungNT", "Menu state rendering...");

		this.getStage().act(delta);
		this.getStage().draw();
	}

	@Override
	public void startAnimation(ButtonEnum buttonEnum) {
		// Animation here

		this.getGame().processMenuButton(buttonEnum);
	}

	@Override
	public void dispose() {
		this.button1.remove();
		this.button1.dispose();
		this.button1 = null;

		this.button2.remove();
		this.button2.dispose();
		this.button2 = null;

		this.button3.remove();
		this.button3.dispose();
		this.button3 = null;

		this.button4.remove();
		this.button4.dispose();
		this.button4 = null;

		this.getStage().dispose();
	}

	@Override
	public void resize() {
		this.getStage().setViewport(Cs.VW, Cs.VH, true, this.getGame().getViewPort().x, this.getGame().getViewPort().y,
				this.getGame().getViewPort().width, this.getGame().getViewPort().height);
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		Gdx.app.log("TrungNT", "Screen was touchUp");
		// Gdx.app.log("TrungNT", "screen: " +screenX + " - " +screenY );
		// Gdx.app.log("TrungNT", "camera: " +touchPosition1.x + " - "
		// +touchPosition1.y );
		// Gdx.app.log("TrungNT", "stage: " +touchPosition2.x + " - "
		// +touchPosition2.y );

		// if (this.button1.isTouched(touchPosition2.x, touchPosition2.y)) {
		// this.startAnimation(ButtonEnum.NEWGAME);
		// }
		// else if (this.button2.isTouched(touchPosition2.x, touchPosition2.y))
		// {
		// this.startAnimation(ButtonEnum.RANKING);
		// }
		// else if (this.button3.isTouched(touchPosition2.x, touchPosition2.y))
		// {
		// this.startAnimation(ButtonEnum.HOWTOPLAY);
		// }
		// else if (this.button4.isTouched(touchPosition2.x, touchPosition2.y))
		// {
		// this.startAnimation(ButtonEnum.EXIT);
		// }

		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		Gdx.app.log("TrungNT", "Screen was touchDown");
		return false;
	}
}
